package com.abss.vote.util;


import com.abss.vote.model.MpInfo;

import java.util.List;

public class WxLogin {


    /**
     * 获取code
     * @return
     */
    public static String getcode(String state, MpInfo mp){
        //将服务器信息添加到session中
//        MpInfo mp = new MpInfo();
//        try {
//            List<String> ls= FileUtils.getBanner();//获取配置文件中的数据
//            mp.setSERVER_ID(ls.get(0));
//            mp.setSERVER_NAME(ls.get(1));
//            mp.setMP_APP_ID(ls.get(2));
//            mp.setMP_APP_SECRET(ls.get(3));
//            mp.setWXCALLBACK(ls.get(4));
//        }catch (Exception e){
//            e.printStackTrace();
//        }

        return "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                "appid=" +mp.getMP_APP_ID()+
                "&redirect_uri=" + mp.getWXCALLBACK()+
                "&response_type=code"+
                "&scope=snsapi_userinfo" +
                "&state="+state+"#wechat_redirect";
    }

    /**
     * 获取access_token
     * @return
     */
    public static String getoken(String code, MpInfo mp){

        //将服务器信息添加到session中
//        MpInfo mp = new MpInfo();
//        try {
//            List<String> ls= FileUtils.getBanner();//获取配置文件中的数据
//            mp.setSERVER_ID(ls.get(0));
//            mp.setSERVER_NAME(ls.get(1));
//            mp.setMP_APP_ID(ls.get(2));
//            mp.setMP_APP_SECRET(ls.get(3));
//            mp.setWXCALLBACK(ls.get(4));
//        }catch (Exception e){
//            e.printStackTrace();
//        }

        return "https://api.weixin.qq.com/sns/oauth2/access_token?" +
                "appid=" +mp.getMP_APP_ID()+
                "&secret=" +mp.getMP_APP_SECRET()+
                "&code=" +code+
                "&grant_type=authorization_code";
    }

    /**
     * 获取用户信息
     * @param ACCESS_TOKEN
     * @param OPENID
     * @param lang
     * @return
     */
    public static String getuserinfo(String ACCESS_TOKEN,String OPENID,String lang){
        return "https://api.weixin.qq.com/sns/userinfo?" +
                "access_token=" +ACCESS_TOKEN+
                "&openid=" +OPENID+
                "&lang="+lang;
    }
    /**
     * 获取用户信息(是否关注)
     * @param ACCESS_TOKEN
     * @param OPENID
     * @return
     */
    public static String getuse(String ACCESS_TOKEN,String OPENID){
        return "https://api.weixin.qq.com/cgi-bin/user/info?" +
                "access_token=" +ACCESS_TOKEN+
                "&openid=" +OPENID;
    }


}
